#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include "params.h"
#include "consts256.h"
#include "neon_ntt.h"
#include "util.h"


int main(void)
{
    poly in, out1;
    nttpoly out;
    int16_t gold_ntt[256] = {
    -8597,  -699,   777,  -358, -4404,  5342,  6732, -10769, 
    -246,   749,  -898, -1938, -2023,  4946, -13239,  6494, 
    1687, -2963,  6065,  8088,  8024,  5316,   656, -1153, 
    1952, -2827, -11286,   436,  6593,   -60, -4295, 13006, 
    -2038, -4381, -1213,  3480, -3508,  5103, -4490,  -761, 
    112,  -230,  -573, -8954,  1000,  3380,  5541, -2412, 
    -1660, -4921,  5243, -5718,  1916,  6023, -6322,   -13, 
    -2742,  5600, -4515, -4324, -2418,    30, -1619,  3852, 
    10578, -6117, 10084,  5552,  7398,  2435,  3799,  3142, 
    3289, -4613, 10596,   924,  5371, 10454,  5945,   579, 
    -4384, 11155,  4870, -8382, -11118, -5355,   973, -2736, 
    11789, -3673,  3110, -17720,  -221,  3478,  9407, -8681, 
    6284, -3276, -2300,  9975,  3409, -1671, -5007, -1843, 
    -784, 11284,  4673, -5082, -9640, -3164, -2124, -4355, 
    7186,  2946,  -842,  -685, 12919, -7241,    51, -4643, 
    -5466,   846, -3571,  1798, -5086,   744,  5632, -7871, 
    11032, -1218,  2479, -15110, -1253,   358, -1172, 11747, 
    1334, -2266,  3768,  -409,  9038,  2791,  3738,   565, 
    -4072,  7654,  1865,  1276,  2907,  1464, -1844, -5005, 
    -3330,  8934,  2218,  6057, -1526,  8735,  -640, -3597, 
    6306,  1050, -5418, -6948, -3298,  3389,    36,  1062, 
    6740,  4623,  1245,  8765,  -925, -1094,  4168, -1613, 
    -3698, 11446,  4682,  2174, -1868,  5169, -5300,   760, 
    6440,  5681,  4673,  7043, -10331,  8684, -1550, -12367, 
    -4366, -1482,  1994, -2642,  1719, -1811,  7587,  8106, 
    -11811, 15130,  5557,  7981,  6550,  5175, -4886,  4911, 
    7824, -1896, -4914, 11306, -6363, -3661, -13871, -1256, 
    -8565, -3468,  5533,  -913,  6618, -5671,  7862, -3387, 
    12508,  4311,  2438, -6975,  2480,  5347,   110,  8296, 
    2854, -6445,   381, -1884, -3253,  3978, 12477,  1635, 
    4458,   587, 10718,  2495, -4336, -3003,  2462,  2202, 
    -3362,  4147,  5609,  8372, -2695,  3042,  1787,  -195,
    };
    
    int16_t gold_invntt[256] = {
    -2938, -2040,  -570, -4564, -1137,  1527,  5733,  5566, 
    566, -3166,  -951,  -309,  3217, -2517, -5665, -5786, 
    2420,   645, -7269, -1538,  5179, -6650,  7952,  1078, 
    5727, -3460, -1011,   881,     8, -4572, -6980, -5375, 
    -8432,  2968,  6700, -1273, -3703, -4257, -4336,  6827, 
    -11881, -4117,   993,  3760,  2960,  8190, -6435, 10775, 
    -15469, -6391, -1279, -3747,  2196,  9353, -2725, -5206, 
    3024,  4702, -8159, -16580,  -264, -4757,  2304,  -452, 
    5114,    53, -4709, -1273,  1575,  1266,  -596,  1521, 
    5648,  5017, -1948,  6048,  3353, -4850,  6658,   749, 
    -2079,  4279,  2120, -8040,   464,  -632,  2227, -6247, 
    -542, -4280, -4249, -1352,  7676,  2556, -2379,  5413, 
    -5722,  -513,  3330, -1114,  2409,  2990, -3161,  2109, 
    -1092,  -716,  2478, -1429,  3183, -6711,  5776, -6342, 
    535,  7595,  7293,   194, -6107,  7186,  4889, -1988, 
    2343, -5896,  2831,  3777,  1014, -5308,  1590, -3099, 
    -3128,  5237, -1051,  2153, -2384,  5098,  -857,  1858, 
    3842,  3570, -2657, -2258,  -423,  4839,  1330,   440, 
    -4636,  3957,  1664, -1671, -3002,  2582,  2956,   512, 
    -4283, -3983,  4856,  4208, -1926, -5229,  1555, -3177, 
    2939,  1570,  4168,  1732,   964,  1288,  2277,   938, 
    125,   679,  5303, -2642, -2808,  2640, -2709,   937, 
    -767,   965, -3625, -2478, -3846,  3432, -1279, -1285, 
    4591, -2518, -1234,  3110,  -487,  2896,  4559,  4097, 
    -2348, -3477,  -387, -4268,  4534, -5325, -3716, -1317, 
    1202,  -569,  1589, -4188,    25,  4237,  3982, -1402, 
    3345, -1856, -4694,  3416,  2036, -2407, -2145, -2924, 
    5340,  -494,  2676,  1384, -1027,  2593,  1462,  2306, 
    -3193, -3157, -3899,  3000, -1429,  5199,  3949, -1633, 
    2840,  1458, -5342,  3370, -4575,  3576,  -645, -2112, 
    4455,  5241,  2322,  3592,  2199,  3131,  2770, -5094, 
    -1207, -4371, -1842,  2667,  -983,  3471,  3735, -3539, 
    };
    
    srand(0);

    printf("srand(0) in MacOS is different than in Linux\n");

    for (int16_t i = 0; i < 256; i++){
        in.coeffs[i] = rand() % P10753;
    }

    neon_ntt(&out, &in, PDATA10753);

    if (compare_array(out.coeffs, gold_ntt)){
        printf("NTT ERROR\n");
        return 1;
    }
    printf("NTT OK\n");


    neon_invntt(&out1, &in, PDATA10753);
    
    if (compare_array(out1.coeffs, gold_invntt)){
        printf("INV NTT ERROR\n");
        return 1;
    }
    printf("INVNTT OK\n");


    return 0;
}
